
const express = require('express');
const routers = require('./router');

class MockServer {
  app;

  constructor() {
    this.app = express();

    app.use( (req, res, next) => {
      console.log(`request from ip ${req.ip} for ${req.url}`);
      next();
    });
      
    app.get('/', (req, res) => {
      res.send('Hello World!');
    });
      
    routers.forEach((router, index) => {
      app.use(router.path, router.application);
    });
  }

  start(port) {
    app.listen(port, () => {
      console.log(`mock server listening ${chalk.blue('http://localhost:')}${chalk.blue(port)}`);
    });
  }
};

module.exports = MockServer;